import { _decorator, Component, director, Label, Node, tween, v3 } from 'cc';
import { back } from './back';
const { ccclass, property } = _decorator;

@ccclass('j9')
export class j9 extends back {
    @property(Node)
    item1: Node = null;
    @property(Label)
    aLabel:Label;

    speedFlag = true;
    oldTick = director.tick;
    start() {
        director.tick = (dt: number) => {
            //注意,这里使用了call.原来director.tick的原对象this是director,这里不用call,this就变成window了
            this.oldTick.call(director, dt * (this.speedFlag ? 1 : 0.33));
        }

        tween(this.item1)
            .to(1.5, { position: v3(250, 100, 0) })
            .to(1.5, { position: v3(-250, 100, 0) })
            .union()
            .repeatForever()
            .start();

        this.aLabel.string = '当前为正常速度，物体 3 秒往复运动'
      
        this.schedule(() => {
            this.speedFlag = !this.speedFlag;
            if (this.speedFlag) {
                this.aLabel.string = '当前为正常速度，物体 3 秒往复运动'
            } else {
                this.aLabel.string = '当前为正常的 0.33 倍速度，游戏中所有 dt 数值受到影响'
            }
        }, 3);
    }

    update(deltaTime: number) {
        
    }
    onDestroy() {
        director.tick = this.oldTick;
    }
}


